<?php

namespace App\Http\Admin\Controllers\Order;


use App\Exceptions\InvalidRequestException;
use App\Http\Admin\Services\Order\OrderService;
use App\Http\Controllers\Controller;
use App\Http\Models\Feedback;
use Illuminate\Http\Request;


class OrderFeedbackController extends Controller
{

    public function index(){
        return view('order.feedback');
    }

    public function list(Request $request){
        $conditions = $request->all();

        $query = Feedback::query();
        if(!empty($conditions['start_time'])){
            $query->where('created_at','>',$conditions['start_time']);
        }
        if(!empty($conditions['end_time'])){
            $query->where('created_at','<',$conditions['end_time']);
        }

        $result = $query->orderBy('created_at','desc')->paginate(20);

        return res('list',$result);
    }


    /*
     * 回复反馈
     * */
    public function answer(Request $request){
        $conditions = $request->all();

        if(empty($conditions['answer']) || empty($conditions['id'])){
            throw new InvalidRequestException('参数缺失');
        }
        Feedback::where('id',$conditions['id'])->update(['answer'=>$conditions['answer']]);

        return res('ok');
    }


}